home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 104_01 / c3.c < prev    next >
Text File  |  1980-01-01  |  5KB  |  280 lines

  1. /*    >>>> start of cc3 <<<<<<<<<    */
  2. /*                    */
  3. #ifndef TRUE    /* see if need include file */
  4. #include <C.DEF>
  5. #endif
  6. /*    Perform a function call        */
  7. /*                    */
  8. /* called from heir11, this routine will either call    */
  9. /*    the named function, or if the supplied ptr is    */
  10. /*    zero, will call the contents of HL        */
  11. callfunction(ptr)
  12. char *ptr;      /* symbol table entry (or 0) */
  13. {
  14.     int nargs;
  15.     nargs=0;
  16.     blanks();        /* already saw open paren */
  17.     if (ptr==0) push();    /* calling HL */
  18.     while (streq(line+lptr,")") == 0) {
  19.         if (endst()) break;
  20.         expression();    /* get an argument */
  21.         if (ptr == 0) swapstk(); /* don't push addr */
  22.         push();        /* push argument */
  23.         nargs=nargs+2;    /* count args*2 */
  24.         if (match(",") == 0) break;
  25.         }
  26.     needbrack(")");
  27.     if (ptr) call(ptr); else callstk();
  28.     sp=modstk(sp+nargs);    /* clean up arguments */
  29.     }
  30. junk()
  31. {       if(an(inbyte())) while(an(ch())) gch();
  32.     else while(an(ch()) == 0) {
  33.         if(ch() == 0) break;
  34.         gch();
  35.         }
  36.     blanks();
  37.     }
  38. endst()
  39. {
  40.     blanks();
  41.     return ((streq(line+lptr,";") ||(ch() == 0)));
  42.     }
  43. suberror(sname)
  44. char *sname;
  45. {
  46.     char msg[80];
  47.  
  48.     strcpy(msg,"identifier \"");
  49.     strcat(msg,sname);
  50.     strcat(msg,"\" is not a vaild array base");
  51.     error_prt(msg);
  52.     while(1) {
  53.         if (endst()) return;
  54.         if (ch()==']') {
  55.             gch();
  56.             return;
  57.             }
  58.         gch();
  59.         }
  60.     }
  61.  
  62. illname()
  63. {
  64.     error("illegal symbol name");
  65.     junk();
  66.     }
  67. undefine(sname)
  68. char *sname;
  69. {
  70.     char msg[80];
  71.     strcpy(msg,"undefine identifier \"");
  72.     strcat(msg,sname);
  73.     strcat(msg,"\"");
  74.     error_print(msg);
  75.     }
  76. /*                        */
  77. /*    written By Mike Bernson 4/81        */
  78. /*                        */
  79. multidef(sname)
  80. char *sname;
  81. {
  82.     char msg[80];
  83.     strcpy(msg,"already defined symbol or function \"");
  84.     strcat(msg,sname);
  85.     strcat(msg,"\"");
  86.     error_print(msg);
  87.     }
  88. needbrack(str)
  89. char *str;
  90. {
  91.     if (!match(str)) error("missing braket");
  92.     }
  93. needlval()
  94. {
  95.     error("must be lvalue");
  96.     }
  97. findglb(sname)
  98. char *sname;
  99. {
  100.     char *ptr;
  101.     ptr=startglb;
  102.     while(ptr!=glbptr) {
  103.         if (astreq(sname,ptr,namemax)) return ptr;
  104.         ptr=ptr+symsiz;
  105.         }
  106.     return 0;
  107.     }
  108. findloc(sname)
  109. char *sname;
  110. {
  111.     char *ptr;
  112.     ptr=startloc;
  113.     while(ptr!=locptr) {
  114.         if(astreq(sname,ptr,namemax))return ptr;
  115.         ptr=ptr+symsiz;
  116.         }
  117.     return 0;
  118.     }
  119. /* Test if next input string is legal symbol name */
  120. symname(sname)
  121. char *sname;
  122. {
  123.     int k;char c;
  124.     blanks();
  125.     if (!alpha(ch())) return 0;
  126.     k=0;
  127.     while(an(ch())) sname[k++]=gch();
  128.     sname[k]=0;
  129.     return 1;
  130.     }
  131. /* Return next avail internal label number */
  132. getlabel()
  133. {
  134.     return (++nxtlab);
  135.     }
  136. /* Print label at start of line */
  137. sprintlabel(label)
  138. int label;
  139. {
  140.     printlabel(label);
  141.     col();
  142.     nl();
  143.     }
  144. /* Print specified number as label */
  145. printlabel(label)
  146. int label;
  147. {
  148.     outstr("@");
  149.     outdec(label);
  150.     }
  151. /* Test if given character is alpha */
  152. alpha(c)
  153. char c;
  154. {
  155.     return((c>='a' && c<='z') ||
  156.         (c>='A' && c<='Z') || c=='_');
  157.     }
  158. /* Test if given character is numeric */
  159. numeric(c)
  160. char c;
  161. {
  162.     return(c>='0' && c<='9');
  163.     }
  164. /* Test if given character is alphanumeric */
  165. an(c)
  166.     char c;
  167. {       return(alpha(c) || numeric(c));
  168.     }
  169. /* Print a carriage return and a string only to console */
  170. pl(str)
  171. char *str;
  172. {
  173.     putch('\r');
  174.     while (*str) putch(*str++);
  175.     }
  176. addwhile(ptr)
  177.     int ptr[];
  178. {
  179.     int k;
  180.     if (wqptr==wqmax) {
  181.         error("too many active whiles");
  182.         return;
  183.         }
  184.     k=0;
  185.     while (k<wqsiz) *wqptr++ = ptr[k++];
  186.     }
  187. delwhile()
  188. {
  189.     if (readwhile()) wqptr=wqptr-wqsiz;
  190.     }
  191. readwhile()
  192. {
  193.     if (wqptr==wq) {
  194.         error("no active while");
  195.         return 0;
  196.         }
  197.     else return wqptr-wqsiz;
  198.     }
  199. ch()
  200. {
  201.     return line[lptr];
  202.     }
  203. nch()
  204. {
  205.        if(ch() == 0) return 0;
  206.     else return(line[lptr+1]);
  207.     }
  208. gch()
  209. {       if(ch() == 0) return 0;
  210.     else return line[lptr++];
  211.     }
  212. kill()
  213. {       lptr=0;
  214.     line[0]=0;
  215.     }
  216. inbyte()
  217. {
  218.     while (!line[lptr]) {
  219.         if (eof) return 0;
  220.         inline();
  221.         preprocess();
  222.         }
  223.     return gch();
  224.     }
  225. inchar()
  226.     {
  227.     if (!line[lptr]) inline();
  228.     if (eof) return 0;
  229.     return (gch());
  230.     }
  231. inline()
  232. {
  233.     int k;
  234.     char *unit;
  235.     while(1) {
  236.         kill();
  237.         if (input==0)openin();
  238.         if (eof) return;
  239.         if (input2) {
  240.             unit=finp2;
  241.             line2++;
  242.             }
  243.         else {
  244.             unit=finp;
  245.             line1++;
  246.             }
  247.         while((k=getc(unit)) != ERROR) {
  248.             if((k=='\n') || (lptr>=linemax)
  249.                 || (k==26)) break;
  250.             if (k != '\r') line[lptr++]=k;
  251.             }
  252.         line[lptr]=0;   /* append null */
  253.         if(k<=0 || k==26) {
  254.             if (input2) {
  255.                 close(input2);
  256.                 input2=0;
  257.                 }
  258.             else {
  259.                 close(input);
  260.                 input=0;
  261.                 }
  262.             }
  263.         if(lptr) {
  264.             if(ctext && cmode) {
  265.                 comment();
  266.                 tab();
  267.                 outstr(line);
  268.                 nl();
  269.                 }
  270.             lptr=0;
  271.             return;
  272.             }
  273.         }
  274.     }
  275. zs,j;
  276.     char c;
  277.     j=zs=0;
  278.     k=10000;
  279.     if (number<0) {
  280.         num